/*
 *               ____
 *              /\   \
 *             ___\   \___
 *            /\          \
 *            \ \___    ___\
 *        ____ \/__/\   \__/
 *       /\   \    \ \___\    klof  |  innovative web technology
 *      ___\   \___ \/___/
 *     /\          \          klib3/style.js
 *     \ \___    ___\         HTML Element style manipulation
 *      \/__/\   \__/
 *          \ \___\           Copyright 2003-2006, klof
 *           \/___/           http://www.klof.net/k.lib3/
 *
 */


/* Create the master klib3 object if she doesn't exist */
if ( typeof klib3 != "object" )
	klib3 = new ( function(){ this._child = 0 } )();



klib3.style = function()
{
	this._version = "1.0.1";
};
klib3.style.prototype.get = function( oElement, sProperty )
{
	if ( typeof document.defaultView == "object" && typeof document.defaultView.getComputedStyle != "undefined" )
	{
		var oCS = document.defaultView.getComputedStyle( oElement, "" );
		if ( oCS && oCS.getPropertyValue )
			return oCS.getPropertyValue( this.cssProperty( sProperty ) );
	}
	else if ( oElement.currentStyle )
	{
		return oElement.currentStyle[ this.scriptProperty( sProperty ) ];
	}
	return false;
};
klib3.style.prototype.set = function( oElement, sProperty, mValue )
{
//	alert( this.scriptProperty( sProperty ) );
//	alert( oElement.style );
	return oElement.style[ this.scriptProperty( sProperty ) ] = mValue;
};
klib3.style.prototype.scriptProperty = function( sProperty )
{
	var n = 0;
	while( ( n = sProperty.indexOf( "-", n ) ) >= 0 )
		sProperty = sProperty.substr( 0, n ) + sProperty.charAt( ++n ).toUpperCase() + sProperty.substring( n + 1 );
	return sProperty;

//  didn't work in older Safari's/IE's (besides.. having a anonymous function for every hyphen in all properties handled is kinda brute)
//	return sProperty.replace( /(-)([a-z])/g, function( a, b, c ){ return c.toUpperCase(); } );
};
klib3.style.prototype.cssProperty = function( sProperty )
{
	return sProperty.replace( /([A-Z])/g, "-$1" ).toLowerCase();
};
klib3.style.prototype.propertyExists = function( oElement, sProperty )
{
	return ( typeof oElement.style[ sProperty ] != "undefined" );
};

// construct the klib3.style Object onto itself so we have access to it's members
klib3.style = new klib3.style;
